﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data;

namespace StyleMVVM.Validation.Impl
{
	public class RuleExecutionContext<T> : IRuleExecutionContext<T>
	{
		private readonly IRuleExecutionContext ruleExecutionContext;

		public RuleExecutionContext(IRuleExecutionContext ruleExecutionContext)
		{
			this.ruleExecutionContext = ruleExecutionContext;
		}

		public ValidationState State
		{
			get { return ruleExecutionContext.State; }
			set { ruleExecutionContext.State = value; }
		}

		public string Message
		{
			get { return ruleExecutionContext.Message; }
			set { ruleExecutionContext.Message = value; }
		}

		public T ValidationObject
		{
			get { return (T)ruleExecutionContext.ValidationObject; }
		}

		public void AddValidationPart(IValidationRuleResultPart part)
		{
			ruleExecutionContext.AddValidationPart(part);
		}

		public void AddRequired(string partName, string message)
		{
			ruleExecutionContext.AddRequired(partName, message);
		}

		public void AddError(string partName, string message)
		{
			ruleExecutionContext.AddError(partName, message);
		}

		public void AddWarning(string partName, string message)
		{
			ruleExecutionContext.AddWarning(partName, message);
		}

		public void AddRequired<TProp>(Expression<Func<T, TProp>> partName, string message)
		{
			string part = IReflectionServiceExtensions.GetPropertyAccessPath(partName);

			AddRequired(part, message);
		}

		public void AddError<TProp>(Expression<Func<T, TProp>> partName, string message)
		{
			string part = IReflectionServiceExtensions.GetPropertyAccessPath(partName);

			AddError(part, message);
		}

		public void AddWarning<TProp>(Expression<Func<T, TProp>> partName, string message)
		{
			string part = IReflectionServiceExtensions.GetPropertyAccessPath(partName);

			AddWarning(part, message);
		}
	}
}